]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
quickSettings: Add QuickToggle
authorFlorian Müllner <fmuellner@gnome.org>
Sun, 24 Jul 2022 17:29:50 +0000 (19:29 +0200)
committerMarge Bot <marge-bot@gnome.org>
Tue, 2 Aug 2022 16:05:28 +0000 (16:05 +0000)
Most quick settings items are just buttons with icon, label, and
a particular style. While that's easy enough, a dedicated class
with corresponding properties is more convenient.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2392>

data/theme/gnome-shell-sass/widgets/_quick-settings.scss
js/ui/quickSettings.js

index 66a0ed3080f821babd571f86d77469c931eac1cd..8dc5ff85087a051a8e583ccbee8e7c2f9c25525f 100644 (file)
@@ -6,3 +6,17 @@
   spacing-rows: 3 * $base_padding;
   spacing-columns: 2 * $base_padding;
 }
+
+.quick-toggle {
+  border-radius: 99px;
+  min-width: 11.5em;
+  max-width: 11.5em;
+  min-height: 48px;
+
+  &:checked { @include button(default); }
+
+  & > StBoxLayout { spacing: $base_padding; }
+
+  .quick-toggle-label { font-weight: bold; }
+  .quick-toggle-icon { icon-size: $base_icon_size; }
+}
index 82a235850af516f06befc6c7ea474381694bef24..340d6a375305957f078a9dfcede66039ac1175c8 100644 (file)
@@ -1,9 +1,72 @@
-/* exported QuickSettingsMenu */
-const {Clutter, GLib, GObject, St} = imports.gi;
+/* exported QuickToggle, QuickSettingsMenu */
+const {Atk, Clutter, Gio, GLib, GObject, Pango, St} = imports.gi;
 
 const Main = imports.ui.main;
 const PopupMenu = imports.ui.popupMenu;
 
+var QuickToggle = GObject.registerClass({
+    Properties: {
+        'icon-name': GObject.ParamSpec.override('icon-name', St.Button),
+        'gicon': GObject.ParamSpec.object('gicon', '', '',
+            GObject.ParamFlags.READWRITE,
+            Gio.Icon),
+        'label': GObject.ParamSpec.string('label', '', '',
+            GObject.ParamFlags.READWRITE,
+            ''),
+    },
+}, class QuickToggle extends St.Button {
+    _init(params) {
+        super._init({
+            style_class: 'quick-toggle button',
+            accessible_role: Atk.Role.TOGGLE_BUTTON,
+            can_focus: true,
+            ...params,
+        });
+
+        this._box = new St.BoxLayout();
+        this.set_child(this._box);
+
+        const iconProps = {};
+        if (this.gicon)
+            iconProps['gicon'] = this.gicon;
+        if (this.iconName)
+            iconProps['icon-name'] = this.iconName;
+
+        this._icon = new St.Icon({
+            style_class: 'quick-toggle-icon',
+            x_expand: false,
+            ...iconProps,
+        });
+        this._box.add_child(this._icon);
+
+        // bindings are in the "wrong" direction, so we
+        // pick up StIcon's linking of the two properties
+        this._icon.bind_property('icon-name',
+            this, 'icon-name',
+            GObject.BindingFlags.SYNC_CREATE |
+            GObject.BindingFlags.BIDIRECTIONAL);
+        this._icon.bind_property('gicon',
+            this, 'gicon',
+            GObject.BindingFlags.SYNC_CREATE |
+            GObject.BindingFlags.BIDIRECTIONAL);
+
+        this._label = new St.Label({
+            style_class: 'quick-toggle-label',
+            y_align: Clutter.ActorAlign.CENTER,
+            x_align: Clutter.ActorAlign.START,
+            x_expand: true,
+        });
+        this.label_actor = this._label;
+        this._box.add_child(this._label);
+
+        this._label.clutter_text.ellipsize = Pango.EllipsizeMode.END;
+
+        this.bind_property('label',
+            this._label, 'text',
+            GObject.BindingFlags.SYNC_CREATE);
+    }
+});
+
 const QuickSettingsLayoutMeta = GObject.registerClass({
     Properties: {
         'column-span': GObject.ParamSpec.int(